<template>
  <div class="feedback-form">
    <el-form :model="form" label-width="120px">
      <el-form-item label="反馈类型" required>
        <el-select v-model="form.type" placeholder="请选择反馈类型">
          <el-option label="举报" value="举报" />
          <el-option label="建议" value="建议" />
          <el-option label="问题" value="问题" />
        </el-select>
      </el-form-item>
      <el-form-item label="标题" required>
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="内容" required>
        <el-input v-model="form.content" type="textarea" :rows="5" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import {submitFeedback} from '@/api/feedback.js'
import {useUserInfoStore} from '@/store/userInfo.js'

const userStore = useUserInfoStore()
const form = reactive({
  type: '',
  title: '',
  content: '',
  student_id: userStore.account
})


const onSubmit = async () => {
  const res = await submitFeedback(form)
  if (res.data.status === 0) {
    ElMessage.success(res.data.message)
    onReset()
  } else {
    ElMessage.error(res.data.message)
    onReset()
   }
}

const onReset = () => {
  Object.assign(form, {
    type: '',
    title: '',
    content: ''
  })
}
</script>

<style scoped>
.feedback-form {
  padding: 20px;
}
</style>